<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title>添加考勤</title>
<link rel="stylesheet" type="text/css"
	href="../assets/admin/layui/css/layui.css" />
<link rel="stylesheet" type="text/css" href="../assets/admin/css/admin.css" />
</head>

<body>
	<div class="page-content-wrap" id="asessmentAdd">

		<form class="layui-form" action="" id="">
			<div class="layui-form-item">
				<label class="layui-form-label">请选择员工</label>
				<div class="layui-input-block">
					   <select name="empId" id="empId" lay-verify="required"  lay-search="">
          				<option value="">请选择员工</option>
       				 </select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">考勤时间</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input" lay-verify="required"
						id="asessmentDate" name="asessmentDate" placeholder="请选择考勤时间">
				</div>
			</div>
		<div class="layui-form-item">
				<label class="layui-form-label">考勤类型</label>
				<div class="layui-input-block">
					<select name="asessmentType" lay-verify="required">
						<option value="">请选择考勤类型</option>
						<option value="1">迟到</option>
						<option value="2">早退</option>
						<option value="3">旷工</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">扣除金额</label>
				<div class="layui-input-block">
					<input type="text" name="deductionSalary" lay-verify="required|deductionSalary"
						autocomplete="off" placeholder="请输入扣除金额" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item m-login-btn" style="text-align:center">
				<div class="layui-inline">
					<button class="layui-btn layui-btn-normal" lay-submit lay-filter="addasessment">添加考勤</button>
				</div>
				<div class="layui-inline">
					<button type="reset" class="layui-btn layui-btn-primary  site-demo-active"
					data-type="reset">取消添加</button>
				</div>
			</div>
		</form>

		<hr></hr>
		<h5 style="text-align: center;">@2019.HR</h5>
	</div>
	<script src="../assets/admin/layui/layui.all.js" type="text/javascript"
		charset="utf-8"></script>
<script>
		layui.use(['form', 'layedit', 'laydate'], function(){
		  var form = layui.form
		  ,layer = layui.layer,layedit=layui.layedit; 
		  var $ = layui.jquery;
			var laydate = layui.laydate;
		  //创建一个编辑器
		  var editIndex = layedit.build('LAY_demo_editor');
			//自定义验证规则
			  form.verify({
				  deductionSalary:[
					 /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
					 '请输入正确的金额'
			    ]
			    ,content: function(value){
			      layedit.sync(editIndex);
			    }
			  });
			
			//加载员工选择下拉框
			  $.ajax({
	           //几个参数需要注意一下
	               type: "POST",//方法类型
	               dataType: "json",//预期服务器返回的数据类型
	               url: "/achives/getAllToSelect",//url
	               data: {},
	               success: function (result) {
	               	if (result.code == "0") {
	               		var data=result.data;
	               		$("#empDepart").html('<option value="">请输入/选择员工</option>');
	               		if(data.length>0){
	               			for(i=0;i<data.length;i++){
	               				var temp=data[i];
	               				$("#empId").append('<option value="'+temp.empId+'">'+temp.empName+'(工号:'+temp.empId+')</option>');
	               			}
	               			layui.form.render('select');
	               		}
	               		
	                 }else{
	                 	layer.msg('加载员工信息下拉框失败', {
	                         icon: 5
	                     });
	                 }
	               },
	               error : function() {
	               	layer.msg('加载员工信息下拉框失败', {
	                       icon: 5
	                   });
	               }
	           });
			
			//成立日期
		       laydate.render({
					elem : '#asessmentDate'
		            ,format:'yyyy-MM-dd HH:mm:ss'
		            ,type:'datetime'
		            ,trigger: 'click'
		        });
			  form.on('submit(addasessment)', function(data){
				    var str=JSON.stringify(data.field)
				    var param = JSON.parse(str);
				    param.asessmentStatus=1;
				    $.ajax({
			                //几个参数需要注意一下
			                    type: "POST",//方法类型
			                    dataType: "json",//预期服务器返回的数据类型
			                    url: "/asessment/addAsessment",//url
			                    data: param,
			                    success: function (result) {
			                    	if (result.code == "0") {
			                    		var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				    					parent.layer.close(index);
			                    		parent.layer.msg('添加考勤信息成功');
			                    		parent.layui.table.reload('asessmentList',{page:{curr:1}});
					                    } else if(result.code == "1"){
					                    	layer.msg('信息已存在', {
					                            icon: 5
					                        });
					                    }else{
					                    	layer.msg('服务器错误', {
					                            icon: 5
					                        });
					                    }
			                    },
			                    error : function() {
			                    	layer.msg('服务器错误', {
			                            icon: 5
			                        });
			                    }
			                });
				    
				    return false;
				  });
			//触发事件
				var active = {
					reset : function() {
						var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
						parent.layer.close(index);
						parent.layer.msg('已取消操作');
					}
				};
			  $('#asessmentAdd .layui-btn').on('click', function() {
					var type = $(this).data('type');
					active[type] ? active[type].call(this) : '';
				});
  
});
</script>
</body>

</html>